package com.forward.controller;

import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.*;

import javax.net.ssl.SSLSession;

/**
 * @Author: shafei
 * @Date: 2025/02/05 17:24
 * @description：
 **/

@RestController
@RequestMapping("/doll/products")
public class TestController {

    /**
     * 测试接口
     */
    @RequestMapping(value = "/test", method = RequestMethod.GET)
    public String test(@RequestParam("name") String name) {
        return "Hello " + name;
    }

    @GetMapping("/tls-version")
    public String getTlsVersion(HttpServletRequest request) {
        String tlsVersion = "Unknown";
        try {
            SSLSession sslSession = (SSLSession) request.getAttribute("javax.servlet.request.ssl_session");
            if (sslSession != null) {
                tlsVersion = sslSession.getProtocol();
            }
        } catch (Exception e) {
            // 处理异常
        }
        return "TLS Version: " + tlsVersion;
    }

}
